import { ref } from 'vue'

export function useSettings() {
  // 设置相关状态
  const settings = ref({
    notifications: true,
    autoLogin: false,
    darkMode: false,
    language: 'zh'
  })

  // 更新设置
  const updateSettings = (key: keyof typeof settings.value, value: boolean | string) => {
    ;(settings.value as any)[key] = value
    // 保存到本地存储
    uni.setStorageSync('settings', settings.value)
  }

  // 加载设置
  const loadSettings = () => {
    const savedSettings = uni.getStorageSync('settings')
    if (savedSettings) {
      settings.value = { ...settings.value, ...savedSettings }
    }
  }

  // 重置设置
  const resetSettings = () => {
    settings.value = {
      notifications: true,
      autoLogin: false,
      darkMode: false,
      language: 'zh'
    }
    uni.removeStorageSync('settings')
  }

  return {
    settings,
    updateSettings,
    loadSettings,
    resetSettings
  }
} 